<?php

namespace App\Http\Controllers;

use App\Library\EncryptDecrypt;
use App\Library\Json;
use App\Service\StationService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class StationController extends BaseController
{

    /**
     * 查询电站信息
     * @param StationService $stationService
     * @return \Illuminate\Http\JsonResponse
     */
    public function queryStationsInfo(StationService $stationService)
    {
        $info = Validator::make($this->requestData, [
            'PageNo' => 'required',
            'PageSize' => 'required',
        ], [
            'PageNo.required' => '查询页码必传',
            'PageSize.required' => '每页数量必传'
        ]);
        if ($info->errors()->first()) {
            return $this->jsonData($info->errors()->first());
        }
        $queryStationInfo = $stationService->queryStationsInfo($this->requestData);
        return $this->json($queryStationInfo);
    }

    /**
     * 设备接口状态查询
     * @param StationService $stationService
     * @return \Illuminate\Http\JsonResponse
     */
    public function queryStationStatus(StationService $stationService)
    {
        $info = Validator::make($this->requestData, [
            'StationIDs' => 'required|array',
        ], [
            'StationIDs.required' => '充电站id必传',
            'StationIDs.array' => '充电站id列表必须为数组'
        ]);
        if ($info->errors()->first()) {
            return $this->jsonData($info->errors()->first());
        }
        $queryStationStatus = $stationService->queryStationStatus($this->requestData);
        $queryStationStatus['OperatorID'] = $this->OperatorID;
        return $this->json($queryStationStatus);
    }

    /**
     * 查询业务策略信息
     * @param StationService $stationService
     * @return \Illuminate\Http\JsonResponse
     */
    public function queryEquipBusinessPolicy(StationService $stationService)
    {
        $info = Validator::make($this->requestData, [
            'EquipBizSeq' => 'required',
            'ConnectorID' => 'required',
        ], [
            'EquipBizSeq.required' => '业务策略查询流水号必传',
            'ConnectorID.required' => '充电设备接口编码必传'
        ]);
        if ($info->errors()->first()) {
            return $this->jsonData($info->errors()->first());
        }
        $queryBusinessPolicy = $stationService->queryEquipBusinessPolicy($this->requestData);
        $queryBusinessPolicy['OperatorID'] = $this->OperatorID;
        $queryBusinessPolicy['EquipBizSeq'] = $this->requestData['EquipBizSeq'];
        $queryBusinessPolicy['SuccStat'] = 0;
        $queryBusinessPolicy['FailReason'] = 0;
        $queryBusinessPolicy['ConnectorID'] = $this->requestData['ConnectorID'];
        $queryBusinessPolicy['SumPeriod'] = 2;
        return $this->json($queryBusinessPolicy);
    }
}
